package sistemaweb.servlets;

import java.io.Console;
import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sistemaweb.excepcion.DAOExcepcion;
import sistemaweb.gestion.GestionPersona;

/**
 * Servlet implementation class RegistrarServlet
 */
@WebServlet("/RegistrarServlet")
public class RegistrarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegistrarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String nombre = request.getParameter("nombres");
		String paterno = request.getParameter("apepaterno");
		String materno = request.getParameter("apematerno");
		String sexo = request.getParameter("sexo");
		String correo = request.getParameter("correo");
		String password = request.getParameter("password");
		String tipodoc = request.getParameter("tipodoc");
		String numdoc = request.getParameter("numdoc");				
		String celular = request.getParameter("celular");
		String direccion = request.getParameter("direccion");
							
		int tdoc = 1;
		
		if(tipodoc.equals("DNI")){
			tdoc = 1;
		}
		if(tipodoc.equals("Pasaporte")){
			tdoc = 2;
		}
		
		GestionPersona gestion = new GestionPersona();
		
		try {
			gestion.insertar(nombre, paterno, materno, sexo, correo, password, tdoc, numdoc, celular, direccion);
			response.sendRedirect(request.getContextPath()	+ "/regresar.jsp");
		}catch (DAOExcepcion e){
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
		
	
		
		
	}

}

